
import { FC, ReactNode } from 'react'
import { useLocation, Navigate } from 'react-router-dom';

interface AuthRouteProp {
  children: ReactNode | ReactNode[]
}

export const AuthRoute: FC<AuthRouteProp> = ({ children }) => {
  const location=useLocation();
  const isAuthenticated = true; // 假设这是鉴权的结果，实际中可能从存储或其他方式获取

  if (!isAuthenticated && location.pathname !== '/login') {
    return <Navigate to="/login" state={{ from: location }} replace />;
  }

  return children;
}

export default AuthRoute;
